// Using the closure to map jQuery to $. 
(function ($) {
	// Store our function as a property of Drupal.behaviors.
	Drupal.behaviors.deployment_validating = {
		attach: function(context, settings) {
			$("#progress-bar").progressbar({
				value: false
			});
			
			// hide the cancel button
	//		$('#cancel-validation').hide();
			
			// show the cancel button after x milisec
	//		setTimeout(function() {
	//			$('#cancel-validation').fadeIn();
	//		}, 3000);
			
			
			ticket_id = $("#ticket-id").val();
			pull_status(ticket_id);
	//		setTimeout(function() {pull_status(ticket_id);}, 1000);
			
			function pull_status(ticket_id) {
				$.ajax({
					url: '/drupal/deployment/get_package_status/'+ticket_id, 
					success: function(data) {
						switch (data) {
						case "0":
							break;
						case "1":			// validating
							break;
						case "2":		//failed
							window.location.replace('deployment/deployment/add_failed/'+ticket_id);
							break;
						case "3":			// pending
							window.location.replace('/drupal/deployment/add_success/'+ticket_id);
							break;
						case "4":
							break;
						}
					},
					complete: function() {
						// Schedule the next request when the current one's complete
						setTimeout(function() {pull_status(ticket_id);}, 1000);
					},
				});
			}
		}
	};
}(jQuery));